import articleService from '../../services/article'
import * as types from '../mutation-types'
// initial state
const state = {
  articleItem: {
    categories: []
  }

}

// getters
const getters = {
  // defaultKeys: state=>{
  //   var arr=[];
  //   for(var i=0;i<state.regionTree.length;i++) {
  //       arr.push(state.regionTree[i].id);
  //   }
  //   return arr;
  // }
  // parseDiploma: (state, name)=> {

  //   Enums.diplomas.map(diploma=> {
  //     if (diploma.name == name) {
  //       return diploma;
  //     }
  //   })

  // }

}

// actions
const actions = {
  loadArticleItem({commit}) {
    if(state.articleItem.categories.length===0){
      articleService.loadArticleItemServer(function(data){
        commit(types.LOAD_ARTICLECATEGORY,data)
      });
    }
  }
}

// mutations
const mutations = {
  [types.LOAD_ARTICLECATEGORY] (state, data) {
    state.articleItem.categories = data.data;
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
